package edu.bu.cs673.superkids123.children.view.lessons;

import java.awt.Color;
import java.awt.Graphics;

/**
 * Class NumberGraphics
 * 
 * This class supports displaying number graphics for the CountingLessonView
 * class. Green balls are displayed below the number graphic to help with the
 * counting concept.
 * 
 * @author David Bardwell
 */
public class NumberGraphics {

	private int startingPositionsX[];
	private int startingPositionsY[];
	private static final int DIAMETER = 20;
	private static final int offsetToNextBallX = 25;

	public NumberGraphics(int startingPositionsX[], int startingPositionsY[]) {
		this.startingPositionsX = startingPositionsX;
		this.startingPositionsY = startingPositionsY;
	}

	public void paintNumberGraphics(Graphics g, int startingNumber,
			boolean audioActive, int currentAudioNumber) {

		Color colors[] = { Color.GREEN, Color.GREEN, Color.GREEN };
		
		// Show current audio number in red for visual cue
		if (audioActive) {
			colors[currentAudioNumber] = Color.RED;
		}

		switch (startingNumber) {
		case 1:
			// Need to paint for numbers 1, 2, 3
			// paint for 1
			paintBallAtPosition(g, startingPositionsX[0],
					startingPositionsY[0], colors[0]);

			// paint for 2
			for (int i = 0; i < 2; i++) {
				paintBallAtPosition(g, startingPositionsX[1]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[1]);
			}

			// paint for 3
			for (int i = 0; i < 3; i++) {
				paintBallAtPosition(g, startingPositionsX[2]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[2]);
			}
			break;

		case 4:
			// paint for 4
			for (int i = 0; i < 4; i++) {
				paintBallAtPosition(g, startingPositionsX[0]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[0]);
			}

			// paint for 5
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[1]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[1]);
			}

			// paint for 6
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[2]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[2]);
			}
			paintBallAtPosition(g, startingPositionsX[2],
					startingPositionsY[1], colors[2]);
			break;

		case 7:
			// paint for 7
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[0]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[0]);
			}
			for (int i = 0; i < 2; i++) {
				paintBallAtPosition(g, startingPositionsX[0]
						+ offsetToNextBallX * i, startingPositionsY[1], colors[0]);
			}

			// paint for 8
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[1]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[1]);
			}
			for (int i = 0; i < 3; i++) {
				paintBallAtPosition(g, startingPositionsX[1]
						+ offsetToNextBallX * i, startingPositionsY[1], colors[1]);
			}

			// paint for 9
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[2]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[2]);
			}
			for (int i = 0; i < 4; i++) {
				paintBallAtPosition(g, startingPositionsX[2]
						+ offsetToNextBallX * i, startingPositionsY[1], colors[2]);
			}
			break;
			
		case 10:
			// paint for 10
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[0]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[0]);
			}
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[0]
						+ offsetToNextBallX * i, startingPositionsY[1], colors[0]);
			}

			// paint for 11
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[1]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[1]);
			}
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[1]
						+ offsetToNextBallX * i, startingPositionsY[1], colors[1]);
			}
			paintBallAtPosition(g, startingPositionsX[1],
					startingPositionsY[2], colors[1]);

			// paint for 12
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[2]
						+ offsetToNextBallX * i, startingPositionsY[0], colors[2]);
			}
			for (int i = 0; i < 5; i++) {
				paintBallAtPosition(g, startingPositionsX[2]
						+ offsetToNextBallX * i, startingPositionsY[1], colors[2]);
			}
			for (int i = 0; i < 2; i++) {
				paintBallAtPosition(g, startingPositionsX[2]
						+ offsetToNextBallX * i, startingPositionsY[2], colors[2]);
			}
		}
	}

	public void paintBallAtPosition(Graphics g, int positionX, int positionY,
			Color color) {
		g.setColor(color);
		g.drawOval(positionX, positionY, DIAMETER, DIAMETER);
		g.fillOval(positionX, positionY, DIAMETER, DIAMETER);
	}
}
